/*********************************************
 * THE BEERWARE LICENSE (Revision 42):
 *
 * As long as you retain this notice you can
 * do whatever you want with this stuff. If we
 * meet some day, and you think this stuff is 
 * worth it, you can buy me a drink in return.
 */

#include "object.h"

#include "configuration.h"

extern CConfiguration configuration;


CObject::CObject(dWorldID world, dSpaceID space,
                 double x, double y, double z,
                 OBJECT_TYPE t, OBJECT_COLOR c,
                 double mass)
{
  int direction = 3;

  double R=0.0, L=0.0;

  this->type = t;
  this->color = c;

  switch(this->type)
  {
    case OT_1:
      
      R = (configuration.object_1_tr);
      L = (configuration.object_1_tl);
      break;

    case OT_2:
 
      R = (configuration.object_2_tr);
      L = (configuration.object_2_tl);
      break;

    case OT_3:
 
      R = (configuration.object_3_tr);
      L = (configuration.object_3_tl);
      break;

    default: break;
  }

  this->body = dBodyCreate(world);
  dBodySetPosition(this->body,x,y,z);
  
  dMassSetCappedCylinderTotal(&(this->m), mass, direction, R, L );
  
  dBodySetMass(this->body, &(this->m));

  this->geom = dCreateCCylinder(0, R, L);

  dGeomSetBody(this->geom, this->body);
  
  dSpaceAdd(space,this->geom);

  // TEST
  //dBodySetAngularVel(this->body, 0.01,0.01,0);

  return;
}

CObject::~CObject()
{
  //dBodyDestroy(this->body);

  dGeomDestroy(this->geom);

  return;
}

	
void CObject::set_position(dReal x, dReal y, dReal z)
{
  dBodySetPosition(this->body, x, y, z);

  return;
}

void CObject::set_speed(dReal vx, dReal vy, dReal vz)
{
  dBodySetLinearVel(this->body, vx, vy, vz);

  return;
}
